package com.ld.data.business.data;


import com.alibaba.fastjson.JSONObject;
import com.ld.data.business.file.vo.CallBackReqVo;
import com.ld.data.business.file.vo.EquipmentCommandSendParamReqVo;
import com.ld.data.business.file.vo.EquipmentStatusInfo;
import com.ld.data.business.file.vo.MethodRespVo;
import com.ld.data.utils.HttpUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Tag(name = "数据处理相关接口")
@RestController
public class DataController {

    @GetMapping("/api/centralControl/equipment/getStatus")
    @Operation(summary = "获取设备状态测试用")
    public EquipmentStatusInfo simpleUploadFile(){
        EquipmentStatusInfo statusInfo = new EquipmentStatusInfo();
        statusInfo.setCode("0");
        statusInfo.setMessage("success");
        statusInfo.setStatus(1);
        return statusInfo;
    }

    @PostMapping("/api/centralControl/equipment/sendCommand")
    @Operation(summary = "测试驱动接受命令")
    public MethodRespVo sendCommand(@RequestBody EquipmentCommandSendParamReqVo equipmentCommandSendParamReqVo){
        log.info("接收到指令\n：{}", JSONObject.toJSONString(equipmentCommandSendParamReqVo));
        MethodRespVo statusInfo = new MethodRespVo();
        statusInfo.setCode("0");
        statusInfo.setMessage("success");
        log.info("返回指令中--------->");
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
        }
        // 回调接口
        CallBackReqVo callBackReqVo = new CallBackReqVo();
        callBackReqVo.setCode("0");
        callBackReqVo.setMessage("SUCCESS");
        callBackReqVo.setResult(new JSONObject());

        EquipmentCommandSendParamReqVo sendCommandParams = new EquipmentCommandSendParamReqVo();
        sendCommandParams.setTaskProcessNodeExampleId(equipmentCommandSendParamReqVo.getTaskProcessNodeExampleId());
        sendCommandParams.setProcessNodeExampleRunningId(equipmentCommandSendParamReqVo.getProcessNodeExampleRunningId());
        callBackReqVo.setSendCommandParams(sendCommandParams);
        String postResp = HttpUtils.sendPostConnectTimeout("http:192.168.0.136:8001/external/centralControl/equipment/callBack", JSONObject.toJSONString(callBackReqVo), 300L);
        //log.info("send_command_resp: {}", postResp);
        return statusInfo;
    }
}
